﻿<%@ WebHandler Language="C#" Class="LeaveWord" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public class LeaveWord : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        string CommunityId=context.Request.QueryString["id"];
        int CID;
        if (!int.TryParse(CommunityId, out CID))
        {
            context.Response.End();
        }
        context.Response.ContentType = "text/vnd.wap.wml";
        context.Response.Charset = "utf-8";
        context.Response.Write(
@"<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN' 'http://www.wapforum.org/DTD/wml_1.1.xml'>
<wml>
<head>
<meta http-equiv='Cache-Control' content='max-age=0' forua='true'/>
</head>
<card id='leave' title='社区留言' newcontext='true'><p>"
        );
            
        if (context.Request.ServerVariables["REQUEST_METHOD"].ToUpper() == "GET")
        {
            context.Response.Write(
@"手机号码:
<br/><input emptyok='true' type='text' name='mp' format='*N' value=''/>
<br/>您的留言:
<br/><input emptyok='true' type='text' maxlength='255' name='content'/>
<br/><anchor>提交
<go method='post' href='LeaveWord.ashx?id="
            + CommunityId +
            @"' accept-charset='utf-8'>
<postfield name='mp' value='$(mp)'/>
<postfield name='content' value='$(content)'/>
</go>
</anchor>"
            );
        }
        else
        {
            string MobileNumber, Content;
            MobileNumber = context.Request.Form["mp"];
            Content = context.Request.Form["Content"];
            if (Content == null || Content.Trim().Length == 0)
            {
                context.Response.Write("请输入留言内容<br/><anchor>返回<prev/></anchor>");
            }
            else
            {
                SqlConnection MySqlConnection = new SqlConnection();
                MySqlConnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["GoWLLConnectionString"].ConnectionString;
                MySqlConnection.Open();
                SqlCommand MySqlCommand = new SqlCommand();
                MySqlCommand.CommandType = CommandType.StoredProcedure;
                MySqlCommand.CommandText = "SaveLeave";
                MySqlCommand.Parameters.Add(new SqlParameter("@MobileNumber", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, MobileNumber));
                MySqlCommand.Parameters.Add(new SqlParameter("@Message", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, Content));
                MySqlCommand.Parameters.Add(new SqlParameter("@CommunityID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, CID));
                MySqlCommand.Parameters.Add(new SqlParameter("@Url", SqlDbType.NVarChar, 255, ParameterDirection.Output, true, 0, 0, "", DataRowVersion.Proposed, null));
                MySqlCommand.Connection = MySqlConnection;
                MySqlCommand.ExecuteNonQuery();
                string Url = (string)MySqlCommand.Parameters[3].Value;
                MySqlConnection.Close();
                MySqlCommand.Dispose();
                MySqlConnection.Dispose();
                context.Response.Write("留言提交成功<br/><a href='"+Url+"'>返回社区</a>");
            }
        }
        context.Response.Write("</p></card></wml>");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}